package com.ifnk.portaljava.dapWeb.hlyt.servlet;
/**
 * <p>Title: 接收处理flex页面心跳类</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2010</p>
 *
 * <p>Company: </p>
 *
 * @author WenSheng.Song.hlyt@gmail.com
 * @version 1.0
 */

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


@SuppressWarnings("serial")
public class DelaySession extends HttpServlet {
	private Log loger = LogFactory.getLog(DelaySession.class);

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String cmd = request.getParameter("cmd");
		String clientId = request.getParameter("clientId");
		
		loger.info("resceive keeplive message, clientId: " + clientId);
		if ("destroy".equals(cmd)) {
			request.getSession().invalidate();
		} else {
			HttpSession session = request.getSession(false);
			if(session != null) {
				// this is also for not kick off the socket because by now no heart beat sending
				session.setAttribute(clientId, System.currentTimeMillis() / 1000);
			}
		}
	}

}
